KVM: PPC: Book3S: Fix H_RTAS rets buffer overflow
authorNicholas Piggin <npiggin@gmail.com>
Tue, 20 Jul 2021 10:43:09 +0000 (20:43 +1000)
committerSalvatore Bonaccorso <carnil@debian.org>
Thu, 23 Sep 2021 20:35:21 +0000 (21:35 +0100)
commit61df5d454e05720250e01fd0feae89a0bc58a003
tree5c6341ba65caf102f94399c52baf69d158670a4d
parent6c31f0ff991dff5b9f7e6e05b968424a88bc4524
KVM: PPC: Book3S: Fix H_RTAS rets buffer overflow

Origin: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git/commit?id=c1fbdf0f3c26004a2803282fdc1c35086908a99e
Bug-Debian-Security: https://security-tracker.debian.org/tracker/CVE-2021-37576

commit f62f3c20647ebd5fb6ecb8f0b477b9281c44c10a upstream.

The kvmppc_rtas_hcall() sets the host rtas_args.rets pointer based on
the rtas_args.nargs that was provided by the guest. That guest nargs
value is not range checked, so the guest can cause the host rets pointer
to be pointed outside the args array. The individual rtas function
handlers check the nargs and nrets values to ensure they are correct,
but if they are not, the handlers store a -3 (0xfffffffd) failure
indication in rets[0] which corrupts host memory.

Fix this by testing up front whether the guest supplied nargs and nret
would exceed the array size, and fail the hcall directly without storing
a failure indication to rets[0].

Also expand on a comment about why we kill the guest and try not to
return errors directly if we have a valid rets[0] pointer.

Fixes: 8e591cb72047 ("KVM: PPC: Book3S: Add infrastructure to implement kernel-side RTAS calls")
Cc: stable@vger.kernel.org # v3.10+
Reported-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Gbp-Pq: Topic bugfix/powerpc
Gbp-Pq: Name KVM-PPC-Book3S-Fix-H_RTAS-rets-buffer-overflow.patch
arch/powerpc/kvm/book3s_rtas.c